//Sat 30 Jan 2010 08:43:59 PM CST 
//
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int recursive(vector<int> treats, int days);
int recursiveleft(vector<int> treats, int days);
int recursiveright(vector<int> treats, int days);

int main()
{
	int N;
	cin >> N;
	vector<int> v(N);
	for(int i=0; i<N; i++)
	{
		cin >> v[i];
	}
	cout << recursive(v, 1) << endl;
	return 0;
}
int recursiveleft(vector<int> treats, int days)
{
	int score = days * treats[0];
	if(treats.size() == 1) return score;
	treats.erase(treats.begin());
	score += recursive(treats, days+1);
	return score;
}
int recursiveright(vector<int> treats, int days)
{
	int score = treats[treats.size()-1] * days;
	if(treats.size() == 1) return score;
	treats.erase(treats.begin() + treats.size() - 1);
	score += recursive(treats, days+1);
	return score;
}
int recursive(vector<int> treats, int days)
{
	int score1 = recursiveleft(treats, days);
	int score2 = recursiveright(treats, days);
	return max(score1, score2);
}
